import json
import logging
from datetime import datetime

from VideoHandler.service.video_handler import resolve_integrate, subclip_video, extract_text

logger = logging.getLogger('VideoHandler')

# executor = concurrent.futures.ThreadPoolExecutor(max_workers=4)

def consumer_message(consumer):
    msg = consumer.poll(timeout=.5)
    logger.info(f'now: {str(datetime.now())}' )
    if msg is not None and msg.error() is None:
        logger.info(f'Success message: {msg.value().decode("utf-8")}')
        topic = msg.topic()
        logger.info(f'topic: {topic}')
        if topic == 'integrate_video_newest':
            resolve_integrate(json.loads(msg.value().decode('utf-8')))
        elif topic == 'subclip_video':
            subclip_video(json.loads(msg.value().decode('utf-8')))
        elif topic == 'video_extract':
            extract_text(json.loads(msg.value().decode('utf-8')))